home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / ScianSciences.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  139 lines

  1. /*ScianSciences.c
  2.   Eric Pepke
  3.   September 27, 1992
  4.  
  5.   Contains information on conventions and common knowledge in various sciences.
  6.   (Right now, just Chemistry.)
  7.  
  8.   Note: I couldn't find canonical colors for atoms, so I made most of them
  9.   up.
  10. */
  11.  
  12. #include "Scian.h"
  13. #include "ScianTypes.h"
  14. #include "ScianIDs.h"
  15. #include "ScianLists.h"
  16. #include "ScianArrays.h"
  17. #include "ScianSciences.h"
  18. #include "ScianPeriodicTable.h"
  19. #include "ScianColors.h"
  20. #include "ScianErrors.h"
  21.  
  22. ObjPtr unitsClass, allUnits;
  23.  
  24. #ifdef PROTO
  25. int AtomNameToNumber(char *name)
  26. #else
  27. int AtomNameToNumber(name)
  28. char *name;
  29. #endif
  30. /*Finds the atomic number for atom name.  Returns it or 0*/
  31. {
  32.     int k;
  33.     for (k = 0; k < N_ATOMS; ++k)
  34.     {
  35.     if (0 == strcmp2(name, atomInfo[k] . shortName))
  36.     {
  37.         return k + 1;
  38.     }
  39.     }
  40.     return 0;
  41. }
  42.  
  43. ObjPtr MakeDefaultPalette(units, min, max)
  44. ObjPtr units;
  45. real min, max;
  46. /*Makes a default palette for units from min to max*/
  47. {
  48.     ObjPtr palette;
  49.  
  50.     palette = NewPalette(DEFPALSIZE);
  51.     BlueToRedPalette(palette);
  52.     SetPaletteMinMax(palette, min, max);
  53.  
  54.     return palette;
  55. }
  56.  
  57. ObjPtr MakeAtomicPalette(units, min, max)
  58. ObjPtr units;
  59. real min, max;
  60. /*Makes a default palette for units from min to max*/
  61. {
  62.     ObjPtr palette;
  63.  
  64.     palette = NewAtomicPalette();
  65.  
  66.     return palette;
  67. }
  68.  
  69. #ifdef PROTO
  70. ObjPtr UnitsNameToPalette(char *name, real min, real max)
  71. #else
  72. ObjPtr UnitsNameToPalette(name, min, max)
  73. char *name;
  74. real min, max;
  75. #endif
  76. /*Takes a units name and makes a palette*/
  77. {
  78.     ObjPtr unitsToView;
  79.     FuncTyp method;
  80.     ObjPtr var;
  81.  
  82.     unitsToView = unitsClass;
  83.  
  84.     if (name && *name)
  85.     {
  86.     ThingListPtr runner;
  87.  
  88.     /*Search through list of units for one that matches*/
  89.     runner = LISTOF(allUnits);
  90.     while (runner)
  91.     {
  92.         var = GetVar(runner -> thing, NAME);
  93.         if (var)
  94.         {
  95.         if (0 == strcmp2(GetString(var), name))
  96.         {
  97.             unitsToView = runner -> thing;
  98.         }
  99.         }
  100.         runner = runner -> next;
  101.     }
  102.     }
  103.  
  104.     method = GetMethodSurely("UnitsNameToPalette", unitsToView, UNITSPALETTE);
  105.     if (method)
  106.     {
  107.     return (*method)(unitsToView, min, max);
  108.     }
  109.     else
  110.     {
  111.     return NULLOBJ;
  112.     }
  113. }
  114.  
  115. void InitSciences()
  116. {
  117.     ObjPtr unit;
  118.  
  119.     /*Initialize the units*/
  120.     unitsClass = NewObject(NULLOBJ, 0L);
  121.     AddToReferenceList(unitsClass);
  122.     SetMethod(unitsClass, UNITSPALETTE, MakeDefaultPalette);
  123.  
  124.     allUnits = NewList();
  125.     AddToReferenceList(allUnits);
  126.  
  127.     /*Make atomic number units*/
  128.     unit = NewObject(unitsClass, 0L);
  129.     SetVar(unit, NAME, NewString("Atomic number"));
  130.     SetMethod(unit, UNITSPALETTE, MakeAtomicPalette);
  131.     PrefixList(allUnits, unit);
  132. }
  133.  
  134. void KillSciences()
  135. {
  136.     RemoveFromReferenceList(allUnits);
  137.     RemoveFromReferenceList(unitsClass);
  138. }
  139.